home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / patch / ppak25_1.lha / PhonePak_2.5 / rexxForwarding.ppak < prev    next >
Text File  |  1994-05-18  |  7KB  |  173 lines

  1. /****************************************************************************/
  2. /*  PhonePak ARexx script for Message Forwarding                            */
  3. /*                                                                          */
  4. /*  LineMan is expecting a result string consisting of a number and a       */
  5. /*  message.  PhonePak's schedule listing can display a message up to 15    */
  6. /*  characters long.  If the number is less than zero, the error is         */
  7. /*  considered fatal and no further attempts will be made.  Zero means      */
  8. /*  success; the forwarding liability will be reset.  Greater than zero     */
  9. /*  represents the number of minutes to wait before trying again; this is   */
  10. /*  therefore a retriable error.                                            */
  11. /****************************************************************************/
  12.  
  13. /***************/
  14. /*  Constants  */
  15. /***************/
  16.  
  17. interval = 10                           /* Minutes before next attempt */
  18. maxlines = 5                            /* Maximum number of phone lines */
  19. maxattempts = 15                        /* Maximum number of retries */
  20.  
  21. /****************************************************************************/
  22.  
  23. options failat 101
  24. options results
  25.  
  26. arg PhoneNumber                             /* Get args handed in by LineMan */
  27. Mailbox = GetDirName(PRAGMA('d'))           /* Get mailbox name (current dir) */
  28. Upper Mailbox                               /* Make sure its upper case */
  29.  
  30. /***********************************/
  31. /*  Try to find an available line  */
  32. /***********************************/
  33.  
  34. x = 1
  35. do forever
  36.     PortName = 'LINEMAN.' || x              /* Assemble the port name */
  37.     if show('P', PortName) then do          /* See if the port is present */
  38.         address value PortName              /* Modify host address */
  39.         SETMAILBOX Mailbox                  /* Get mailbox info */
  40.         if rc = 0 then do        
  41.             if word(result,3) = IN then
  42.                 exit interval "'MB is marked IN'"
  43.             else
  44.                 call Forward()              /* Only returns if call should */
  45.             end                             /* be attempted on another line */
  46.         else if rc != 98 & rc != 99 then
  47.             exit "-1 'Script error'"        /* Outer quotes get stripped */
  48.         end
  49.     if x = maxlines then
  50.         exit interval "'Line not avail'"    /* Outer quotes get stripped */
  51.     else
  52.         x = x + 1                           /* Increment line # and continue */
  53.     end
  54.  
  55. /*********************************/
  56. /*  SUBROUTINE                   */
  57. /*  Attempt to forward messages  */
  58. /*********************************/
  59.  
  60. Forward:
  61.     OpString = '<O><D>' PhoneNumber '<C><W15>'
  62.     OPERATOR OpString                           /* Dial the phone number */
  63.     DialResult = rc
  64.  
  65.     if DialResult ~= 0 then                     /* Hang up on error */
  66.         Operator '<H>' 
  67.  
  68.     select
  69.         when DialResult = -3 then               /* Make sure phone # is 'raw' */
  70.             exit "-1 'Procedure error'"      
  71.         when DialResult = -2 then               /* Probably a missing message */
  72.             exit "-1 'I/O error'"      
  73.         when DialResult = -1 then       
  74.             exit "-1 'Syntax error'"      
  75.  
  76.         when DialResult = 0 then     
  77.             nop
  78.         when DialResult = 1 then     
  79.             exit interval "'Resource error'"      
  80.         when DialResult = 2 then     
  81.             exit interval "'Local pickup'"      
  82.         when DialResult = 4 then     
  83.             return      
  84.         when DialResult = 5 then     
  85.             exit interval "'No dialtone'"      
  86.         when DialResult = 6 then do    
  87.             if TryAgain() = TRUE then           /* Limit number of attempts */
  88.                 exit interval "'No answer'"      
  89.             else
  90.                 exit "-1 'Hit retry limit'"      
  91.             end
  92.  
  93.         when DialResult = 8 then do     
  94.             if TryAgain() = TRUE then           /* Limit number of attempts */
  95.                 exit interval "'Busy signal'"      
  96.             else
  97.                 exit "-1 'Hit retry limit'"      
  98.             end
  99.  
  100.         when DialResult = 98 | DialResult = 99 then     
  101.             return      
  102.         otherwise
  103.             exit "-1 'Fatal error'"      
  104.         end
  105.  
  106.     setclip(Mailbox || ATTEMPTS, 0)             /* Reset busy attempts */
  107.  
  108. /****************************************************************************/
  109. /* The called party will hear "x new messages.  Please enter your password  */
  110. /* now" upon answering the phone.  If you would like to make this script    */
  111. /* a little more sophisticated, you could insert a PLAYBACK command here    */
  112. /* to play a message that says something like "This is an automated call    */
  113. /* for John; please call him to the phone."  Note that, although the current*/
  114. /* directory for this script is John's mailbox, LineMan is probably set to  */
  115. /* a different directory.  You can easily set LineMan to John's mailbox by  */
  116. /* issuing the command "CHANGEDIR pragma('d')".  Then you won't need a path */
  117. /* specification for the filename in the PLAYBACK command.  You might play  */
  118. /* the message three times or so, while you wait for John to press 1 or some*/
  119. /* other DTMF code to indicate that the script should proceed.  You could   */
  120. /* even play a message that tells the called party what to do if John is    */
  121. /* not available (e.g., call back in thirty minutes, sixty minutes, or not  */
  122. /* at all), modifying the script's exit code according to the called        */
  123. /* party's response.                                                        */
  124. /****************************************************************************/
  125.  
  126.     REMOTEACCESS Mailbox 51                     /* Initiate remote access */
  127.     RAResult = rc                               /* Stash result */
  128.     Operator '<H>'                              /* Hang up when finished */
  129.  
  130.     select
  131.         when RAResult = -3 then
  132.             exit "-1 'Bad Password'"      
  133.         when RAResult = -2 then            
  134.             exit "-1 'I/O error'"      
  135.         when RAResult = -1 then       
  136.             exit "-1 'Syntax error'"      
  137.         when RAResult = 1 then     
  138.             exit interval "'Resource error'"      
  139.         otherwise
  140.             exit                                /* Success! */                                  
  141.         end
  142.  
  143. /***********************************/
  144. /*  SUBROUTINE                     */
  145. /*  Get name of current directory  */
  146. /***********************************/
  147.  
  148. GetDirName:
  149.     path = arg(1)
  150.     n = lastpos("/",path)
  151.     
  152.     if n=0 then
  153.         n = lastpos(":",path)
  154.         
  155.     return substr(path, n+1)
  156.  
  157. /***********************************/
  158. /*  SUBROUTINE                     */
  159. /*  Determine if retries remain    */
  160. /***********************************/
  161.  
  162. TryAgain:
  163.     x = getclip(Mailbox || ATTEMPTS)
  164.     if x = '' then x = 0
  165.     x = x + 1        
  166.     if x = maxattempts then do
  167.         x = 0
  168.         setclip(Mailbox || ATTEMPTS, x)
  169.         return FALSE
  170.         end
  171.     setclip(Mailbox || ATTEMPTS, x)
  172.     return TRUE      
  173.